package com.ruoyi.epidemic.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.epidemic.mapper.TbPolicyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.epidemic.mapper.TbDefendMapper;
import com.ruoyi.epidemic.domain.TbDefend;
import com.ruoyi.epidemic.service.ITbDefendService;

import javax.annotation.Resource;

/**
 * 应急防护知识Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-21
 */
@Service
public class TbDefendServiceImpl implements ITbDefendService 
{
    @Resource
    private TbDefendMapper tbDefendMapper;

    @Resource
    private TbPolicyMapper tbPolicyMapper;
    /**
     * 查询应急防护知识
     * 
     * @param id 应急防护知识主键
     * @return 应急防护知识
     */
    @Override
    public TbDefend selectTbDefendById(Long id)
    {
        return tbDefendMapper.selectTbDefendById(id);
    }

    /**
     * 查询应急防护知识列表
     * 
     * @param tbDefend 应急防护知识
     * @return 应急防护知识
     */
    @Override
    public List<TbDefend> selectTbDefendList(TbDefend tbDefend)
    {
        return tbDefendMapper.selectTbDefendList(tbDefend);
    }

    /**
     * 新增应急防护知识
     * 
     * @param tbDefend 应急防护知识
     * @return 结果
     */
    @Override
    public int insertTbDefend(TbDefend tbDefend)
    {
        SysUser sysUser = tbPolicyMapper.selectUser(tbDefend.getAdminId());
        tbDefend.setAdminName(sysUser.getUserName());
        return tbDefendMapper.insertTbDefend(tbDefend);
    }

    /**
     * 修改应急防护知识
     * 
     * @param tbDefend 应急防护知识
     * @return 结果
     */
    @Override
    public int updateTbDefend(TbDefend tbDefend)
    {
        return tbDefendMapper.updateTbDefend(tbDefend);
    }

    /**
     * 批量删除应急防护知识
     * 
     * @param ids 需要删除的应急防护知识主键
     * @return 结果
     */
    @Override
    public int deleteTbDefendByIds(Long[] ids)
    {
        return tbDefendMapper.deleteTbDefendByIds(ids);
    }

    /**
     * 删除应急防护知识信息
     * 
     * @param id 应急防护知识主键
     * @return 结果
     */
    @Override
    public int deleteTbDefendById(Long id)
    {
        return tbDefendMapper.deleteTbDefendById(id);
    }

    @Override
    public List<TbDefend> getList(String title) {
        QueryWrapper<TbDefend> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(title)){
            wrapper.like("title",title);
        }
        return tbDefendMapper.selectList(wrapper);
    }


}
